﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Acoris.Foundation
{
    public sealed class OperationStack
    {
        Stack<IOperatorUnit> _undoStack;
        Stack<IOperatorUnit> _redoStack;
        int _length;

        public OperationStack()
        {
            _redoStack = new Stack<IOperatorUnit>();
            _undoStack = new Stack<IOperatorUnit>();
        }

        public void SetOperation(IOperatorUnit unit)
        {
            _undoStack.Push(unit);
            _length++;
        }

        public void Undo()
        {
            var unit = _undoStack.Pop();
            _redoStack.Push(unit);
        }

        public IOperatorUnit Redo()
        {
            var unit = _redoStack.Pop();
            _undoStack.Push(unit);
            return unit;
        }

        public bool CanRedo {
            get {
                return _redoStack.Count > 0;
            }
        }

        public bool CanUndo {
            get {
                return _undoStack.Count > 0;
            }
        }

        public int Count {
            get {
                return _length;
            }
        }
    }
}
